package com.xinqi.service.impl;

import com.xinqi.service.DynamicTpPoolService;
import lombok.extern.slf4j.Slf4j;
import org.dromara.dynamictp.common.em.QueueTypeEnum;
import org.dromara.dynamictp.core.DtpRegistry;
import org.dromara.dynamictp.core.thread.DtpExecutor;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author xin麒
 * @date 2023/8/14 0:42
 */
@Slf4j
@Service
public class DynamicTpPoolServiceImpl implements DynamicTpPoolService {

/*
    @Resource
    private ThreadPoolTaskExecutor xExecutor;

    @Override
    public Object processForCountByDynamicTpPoolInNacos(Long count) {
        xExecutor.execute(()->{
            try {
                Thread.sleep(1000 * 10);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            log.debug("this is execute in pool");
        });

        log.debug("this is a log1");
        return "nice nacos!";
    }*/

    @Override
    public Object processForCountByDynamicTpPoolInNacos(Long count) {
//        QueueTypeEnum
        DtpExecutor xExecutor = DtpRegistry.getDtpExecutor("xExecutor");
        xExecutor.execute(() -> {
            try {
                //

                Thread.sleep(1000 * 10);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            log.debug("this is execute in pool");
        });

        log.debug("this is a log1");
        return "nice nacos!";
    }
}
